﻿using System;
using System.Data;
using System.Collections.Generic;
using System.Web.UI.HtmlControls;
using System.Web.UI;
using System.Web;
using System.Net;


using DevExpress.Web.ASPxHeadline;

using LMD.Lib.DataClass;
using LMD.Constant;
using LMD.Lib.Interface;
using LMD.Lib.Oracle;
using LMD.Lib.Controls;

/// <summary>
/// Summary description for MRTGManager
/// </summary>
public static class MRTGManager
{
    public static String BuildEditor_MRTG()
    {
        String sxOutput = String.Empty;
        String sxOTFComboCustomer = CustomControls.Create_OTFComboBox(
            KMRTG.CUSTOMERID, KLOV.CourtesyCall.COMPANYLIST, null, null, TextboxType.Empty, String.Empty, "SelectCompany()");
        String sxLOVNetwork = CustomControls.Create_OTFComboBox(KMRTG.NETWORK,
            KLOV.ConfigDatek.NETWORK, "", "", TextboxType.Empty, "-1", String.Empty);
        Dictionary<String, String> dicOption = new Dictionary<String, String>();
        dicOption.Add("DAILY", "DAILY");
        dicOption.Add("WEEKLY", "WEEKLY");
        dicOption.Add("MONTHLY", "MONTHLY");
        dicOption.Add("CUSTOM", "CUSTOM");
        String sxComboTime = CustomControls.Create_ComboBox(KMRTG.TIME,
            KControl.INPUT_ID, dicOption, "CUSTOM","SelectTimeRange()");
        String sxStartDate = CustomControls.Create_TextBox(KMRTG.STARTDATE, KControl.INPUT_ID,
            null, true, TextboxType.Date);
        String sxEndDate = CustomControls.Create_TextBox(KMRTG.ENDDATE, KControl.INPUT_ID,
            null, true, TextboxType.Date);
        
        sxOutput += CustomControls.BuildFieldSet_PairedLabel("Company Name", sxOTFComboCustomer);
        sxOutput += CustomControls.BuildFieldSet_PairedLabel("Network No", sxLOVNetwork);
        sxOutput += CustomControls.BuildFieldSet_PairedLabel("Time Range", sxComboTime);
        sxOutput += "<div id=\"divDate\">" + CustomControls.BuildFieldSet_PairedLabel("Start Date", sxStartDate);
        sxOutput += CustomControls.BuildFieldSet_PairedLabel("End Date", sxEndDate) + "</div>";
        sxOutput +=
            "<input type=\"button\" id=\"btnGenerate\" class=\"btn\" " +
            "style=\"float: right; margin-left: 5px; margin-right: 5px;\"" +
                "onclick=\"Generate();\" value=\"GENERATE\" /> "+
            "<div id=\"load1\" style=\"float: right; margin-left: 5px; margin-right: 5px;\"></div>";
        

        return sxOutput;
    }

    public static String BuildImage(String sxNetworkNo, String sxStartDate, String sxEndDate)
    {
        String sxOutput = String.Empty;

        String sxExtraParam = String.Empty;
        if (!String.IsNullOrEmpty(sxStartDate))
        {
            String epchStartDate = ((Convert.ToDateTime(sxStartDate).ToUniversalTime().Ticks - 621355968000000000) / 10000000).ToString();
            String epchEndDate = ((Convert.ToDateTime(sxEndDate).ToUniversalTime().Ticks - 621355968000000000) / 10000000).ToString();
            sxExtraParam = String.Format("&start={0}&end={1}", epchStartDate, epchEndDate);
        }
        sxOutput = String.Format(
            "<img id=\"MRTG.IMAGE\" src=\"{2}{0}{1}\" alt=\"Chart\" width=\"500px\" heigth=\"500px\"><br/>",
            sxNetworkNo,
            sxExtraParam,
            KGlobal.MRTG_URL);

        sxOutput += CustomControls.BuildEditor_LabelAndText(KMRTG.NOTE, KControl.INPUT_ID, "Note", null, TextboxType.Notes);
        sxOutput +=
        "<input type=\"button\" id=\"btnUpload\" class=\"btn\"" + 
        "style=\"float: right; margin-left: 5px; margin-right: 5px;\""+
                "onclick=\"Upload();\" value=\"UPLOAD\" />"+
                "<div id=\"load2\" style=\"float: right; margin-left: 5px; margin-right: 5px;\"></div>";
        return sxOutput;
    }
}
